﻿@model Mulala.Cavan.Presentation.Mvc.ViewModel.INanniesViewModel
@{
    ViewBag.Title = "list";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{
    <title>@ViewBag.Title</title>
}
@{
    string designateID = string.Empty;  
}
@foreach (var nanny in @Model.Nannies)
{
    designateID = "designate" + nanny.Item.ID.ToString();
    <p>@nanny.Item.Name</p>
    <br />
    <p>@nanny.Experience</p>
    <br />
    <input type="button" value="请求合约" id="@designateID" name="designate"/>
    
}
<div id="designateNanny" style="display: none">
    <select id="consigns">
    </select>
    <input type="button" value="确定" id="doDesignate" />
    @Html.Hidden("nannyID", "", new { id = "nannyID" })
</div>
@{
    Html.RenderAction("nannytags", "Tag");
}
@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("input[name='designate']").bind("click", function () {
                var nannyID = $(this).attr("id").substring("designate".length);
                $("#nannyID").val(nannyID);
                getConsigns($("#consigns"));
            });

            $("#doDesignate").bind("click", function () {
                var nannyID = $("#nannyID").val();
                var consignID = $("#consigns").val();
                $.ajax({
                    url: '/proprietorcenter/designatenanny/' + consignID + "/" + nannyID,
                    type: 'POST',
                    success: function (data) {
                        if (data) {
                            alert(data.Messages[0]);
                        }
                    },
                    error: function () {
                        window.location.href = "http://www.mulala.com";
                    }
                });
            });
        });

        function getConsigns(obj) {
            obj.find("option").remove();
            $.ajax({
                url: '/proprietorcenter/biddingconsigns',
                type: 'POST',
                success: function (json) {
                    if (json) {
                        $.each(json.Consigns, function (i, item) {
                            obj.append("<option value=" + item.Value + ">" + item.Text + "</option>");
                        });
                        $("#designateNanny").show();
                    }
                },
                error: function () {
                    window.location.href = "http://www.mulala.com/useraccount/login";
                }
            });
        }
    </script>
}
